package com.zjitc.controller;/**
 * Create by IntelliJ IDEA
 *
 * @author: MaoYongQi
 * @date-Time: 2018/4/2 10:22
 * @description:
 */

import com.github.pagehelper.PageInfo;
import com.zjitc.common.ServerResponse;
import com.zjitc.model.Product;
import com.zjitc.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Create by IntelliJ IDEA
 * @author: MaoYongQi
 * @date-Time: 2018/4/2 10:22
 * @description:
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService service;

    @RequestMapping("/list")
    @ResponseBody
    public ServerResponse list(
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "orderBy",required = false,defaultValue = "")String orderBy){
       ServerResponse<PageInfo<Product>> response =  service.findByList(pageNum,pageSize,orderBy);
       return response;
    }

    @RequestMapping("/detail")
    @ResponseBody
    public ServerResponse<Product> getDetail(Integer productId){
        ServerResponse<Product> response = service.findDetail(productId);
        return  response;
    }

}
